VERSION 5.00
Begin VB.Form p4comTestForm 
   Caption         =   "Test p4 from vb"
   ClientHeight    =   5640
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9570
   LinkTopic       =   "Form1"
   ScaleHeight     =   5640
   ScaleWidth      =   9570
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdSubmit 
      Caption         =   "S&ubmit"
      Height          =   495
      Left            =   5040
      TabIndex        =   8
      Top             =   4920
      Width           =   1455
   End
   Begin VB.CommandButton cmdEnv 
      Caption         =   "&Env"
      Height          =   495
      Left            =   3360
      TabIndex        =   7
      Top             =   4920
      Width           =   1455
   End
   Begin VB.CommandButton cmdClear 
      Caption         =   "Clear"
      Height          =   495
      Left            =   120
      TabIndex        =   6
      Top             =   1320
      Width           =   1455
   End
   Begin VB.CommandButton cmdRun 
      Caption         =   "&Run"
      Default         =   -1  'True
      Height          =   495
      Left            =   1680
      TabIndex        =   4
      Top             =   4920
      Width           =   1455
   End
   Begin VB.TextBox txtCmd 
      Height          =   375
      Left            =   1680
      TabIndex        =   1
      Text            =   "info"
      Top             =   120
      Width           =   5775
   End
   Begin VB.ListBox ResultBox 
      Height          =   3960
      ItemData        =   "p4comTestForm.frx":0000
      Left            =   1680
      List            =   "p4comTestForm.frx":0002
      TabIndex        =   3
      Top             =   720
      Width           =   7335
   End
   Begin VB.CommandButton cmdClose 
      Cancel          =   -1  'True
      Caption         =   "Close"
      Height          =   495
      Left            =   6720
      TabIndex        =   5
      Top             =   4920
      Width           =   1455
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "P4 cmd to execute:"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   975
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "Result:"
      Height          =   375
      Left            =   600
      TabIndex        =   2
      Top             =   720
      Width           =   975
   End
End
Attribute VB_Name = "p4comTestForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'*******************************************************************************
'
' Copyright (c) 2003, Robert Cowham and Vaccaperna Systems Ltd.  All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions are met:
'
' 1.  Redistributions of source code must retain the above copyright
'     notice, this list of conditions and the following disclaimer.
'
' 2.  Redistributions in binary form must reproduce the above copyright
'     notice, this list of conditions and the following disclaimer in the
'     documentation and/or other materials provided with the distribution.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
' ARE DISCLAIMED. IN NO EVENT SHALL VACCAPERNA SYSTEMS LTD. BE LIABLE FOR ANY
' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
' *******************************************************************************
'
' Name: p4comtestform.frm
'
' Author:   Robert Cowham <robert@vaccaperna.co.uk>
'
' Description:
'   Very simple demo of p4com - COM interface to Perforce.
'
'   Executes any command which the users types in txtCmd and puts the results
'   into the ResultBox.
'
'   Please note that there is no real error handling.
' ******************************************************************************

Dim OutputArr() As String
Dim WarningArr() As String
Dim ErrorArr() As String
Dim Files() As String
    
Dim m_p4 As P4COM.p4
Dim m_p4form As P4COM.p4    ' Note this will be used with ParseForms


Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub cmdEnv_Click()
    EnvForm.ShowEnv m_p4
    m_p4form.Charset = m_p4.Charset
    m_p4form.Client = m_p4.Client
    m_p4form.Cwd = m_p4.Cwd
    m_p4form.Host = m_p4.Host
    m_p4form.Language = m_p4.Language
    m_p4form.Password = m_p4.Password
    m_p4form.Port = m_p4.Port
    m_p4form.User = m_p4.User
End Sub

Private Sub cmdRun_Click()
    On Error GoTo error_Block
    Dim Result As Long
    
    m_p4.Connect
    
    OutputArr = m_p4.run(txtCmd.Text)
    DisplayResult
    m_p4.Disconnect
    Exit Sub
error_Block:
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    DisplayResult
End Sub

Private Sub DisplayResult()

    ResultBox.AddItem "Cmd:" & txtCmd.Text
    WarningArr = m_p4.Warnings
    ErrorArr = m_p4.Errors
    DisplayArrayOpt "Output:", OutputArr
    DisplayArrayOpt "Warnings:", WarningArr
    DisplayArrayOpt "Errors:", ErrorArr
    If Len(m_p4.TempFilename) > 0 Then
        ResultBox.AddItem "TempFilename:" & m_p4.TempFilename
    End If
    ResultBox.AddItem " "

End Sub

Private Sub DisplayArray(ByVal msg As String, arr() As String)
    Dim i As Integer

    ResultBox.AddItem msg
    For i = LBound(arr) To UBound(arr)
        ResultBox.AddItem arr(i)
    Next
End Sub

Private Sub DisplayArrayOpt(ByVal msg As String, arr() As String)
    Dim i As Integer

    If UBound(arr) >= LBound(arr) Then
        DisplayArray msg, arr
    End If
End Sub

Private Sub cmdSubmit_Click()
    SubmitForm.DoSubmit m_p4form
    m_p4form.Disconnect
End Sub

Private Sub cmdClear_Click()
    ResultBox.Clear
End Sub

Private Sub Form_Load()
    Set m_p4 = New P4COM.p4
    Set m_p4form = New P4COM.p4
    m_p4.ExceptionLevel = 1
    m_p4form.ExceptionLevel = 1
    m_p4form.ParseForms     ' For use with -o/-i commands.
End Sub

